<template>
	<com-page>
		<view slot="nav" class="response">
			<uni-nav-bar :class="[$themeClass('page-bg-color')]" statusBar="true" :title="i18n.homeTitle"></uni-nav-bar>
		</view>
		<view slot="content" class="response" style="overflow-y: scroll;height:inherit;">
			<home ref="home" v-if="PageCur=='home'"></home>
			<msg ref="msg" v-if="PageCur=='msg'"></msg>
			<mine ref="mine" v-if="PageCur=='mine'"></mine>
		</view>
		<view slot="tabbar" class="response">
			<view class="cu-bar">
				<view class="action" v-for="(item,index) in tabArr" :key="index" @click="NavChange(item.PageCur)" data-cur="substitute">
						<view class='cuIcon-cu-image'>
							<image :src ="PageCur == item.PageCur? item.sPic:item.pic">
								<view class="cu-tag badge" v-if="item.badge!=0">
									<block v-if="item.badge!=1">{{item.badge>99?'99+':item.badge}}</block>
								</view>
							</image>
						</view>
						<view :class="PageCur == item.PageCur?'text-blue':'text-gray'">{{item.title}}</view>				
					</view>
				</view>
			</view>
		</view>
	</com-page>
</template>

<script>
	import home from "./tabbar/home";
	import mine from "./tabbar/mine";
	import msg from "./tabbar/msg";
	export default {
		components: {
		    home,
		    mine,
			msg
		},
		data() {
			return {
				PageCur: '',
				tabArr: [],
			}
		},
		computed: {
			i18n() {
				this.initTab(this.$t('home'))
				return this.$t('home')
			}
		},
		onLoad() {
			this.lang = this._i18n.locale;
			console.log(this.$Route);
			this.$nextTick(function(){
				this.NavChange("home");
			})
			// #ifdef MP-WEIXIN
			// uni.getSetting({
			// 	withSubscriptions: true,
			// 	success(res) {
			// 		// console.log(res.authSetting)
			// 		console.log(res.subscriptionsSetting)
			// 		if(res.subscriptionsSetting.mainSwitch){
			// 			// 订阅是打开状态
			// 			if(res.subscriptionsSetting.itemSettings != null){
			// 				// 每一项开关
			// 				console.log(res.subscriptionsSetting.itemSettings);
			// 				// 每一项订阅消息的订阅状态。itemSettings对象的键为一次性订阅消息的模板id或系统订阅消息的类型，值为'accept'、'reject'、'ban'中的其中一种。'accept'表示用户同意订阅这条消息，'reject'表示用户拒绝订阅这条消息，'ban'表示已被后台封禁。
			// 				// uni.requestSubscribeMessage({
			// 				//   tmplIds: ['DfjxyK2l4s2tE9JzBD0-Jjck222Wo2M1WoZQL9ErH1I'],
			// 				//   success (res) { 
			// 				// 	  console.log(res);
			// 				//   }
			// 				// });
			// 			}
			// 		}
			// 	}
			// })
			// #endif
			if(this.$Route.query.scene){
				this.$store.dispatch('setMainScene', this.$Route.query.scene);
			}
		},
		methods: {
			initTab(i18n){
				this.tabArr = [{
					title: i18n.tabbarHome,
					pic: "/static/img/tabbar/home.svg",
					sPic: "/static/img/tabbar/home_cur.svg",
					badge: 0,
					PageCur: "home",
				},{
					title: i18n.tabbarItyw,
					pic: "/static/img/tabbar/msg.svg",
					sPic: "/static/img/tabbar/msg_cur.svg",
					badge: 0,
					PageCur: "msg",
				},{
					title: i18n.tabbarMine,
					pic: "/static/img/tabbar/mine.svg",
					sPic: "/static/img/tabbar/mine_cur.svg",
					badge: 0,
					PageCur: "mine",
				}];
			},
			NavChange: function(e) {
				this.PageCur = e;
			}
		}
	}
</script>

<style>
.index-badge{
	position: absolute;
	right: 20upx;
	top: 2upx;
	font-size: 10upx;
	height: 32upx;
	border-radius: 200upx;
}
</style>
